package com.longcai.controller.nearbyshop;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.longcai.bean.ApiResult;
import com.longcai.entity.nearby.vo.ClyjNearbyPackageQueryVo;
import com.longcai.entity.nearby.vo.ClyjNearbyPackageVo;
import com.longcai.service.nearbyshop.ClyjNearbyPackageService;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/****
 * 团购
 *
 */
@Controller
@RequestMapping("/clyjNearbyPackage")
public class ClyjNearbyPackageController {

	@Autowired
	private   ClyjNearbyPackageService	clyjNearbyPackageService;
	
	/****
	 * 查询团购商品列表
	 * @param clyjNearbyPackageVo
	 * @return
	 */
	  @RequestMapping("/getNearbyPackageList")
	  @ResponseBody
	  public ApiResult<?> getNearbyPackageList(@RequestBody ClyjNearbyPackageQueryVo clyjNearbyPackageVo ){
		  ApiResult<?> r=  clyjNearbyPackageService.queryNearbyPackageList(clyjNearbyPackageVo);
		  return r;
	  }
	  
	  /****
	   * 初始化团购商品列表，   分栏数量(在售数量，未审核数量，仓库中数量)
	   * @param clyjNearbyPackageVo
	   * @return
	 */
	  @RequestMapping("/queryNearbyPackageCount")
	  @ResponseBody
	  public Map<String, Integer>  queryNearbyPackageCount(){
		  Map<String, Integer>  r=  clyjNearbyPackageService.queryNearbyPackageCount();
		  return r;
	  }
		  
	  
	  /****
	   * 修改团购商品
	   * @param clyjNearbyPackageVo
	   * @return
	 * @throws Exception 
	 */
	  @RequestMapping("/updateNearbyPackage")
	  @ResponseBody
	  public ApiResult<?> updateNearbyPackage(@RequestBody ClyjNearbyPackageVo clyjNearbyPackageVo,MultipartFile[]  packageBanner,MultipartFile mainPushPic) throws Exception{
		 ApiResult<?> r=  clyjNearbyPackageService.updateNearbyPackage(clyjNearbyPackageVo,packageBanner,mainPushPic);
		  return r;
	  }
	  
	  /****
	   * 保存团购商品
	   * @param clyjNearbyPackageVo
	   * @return
	 * @throws Exception 
	 */
	  @RequestMapping("/saveNearbyPackage")
	  @ResponseBody
	  public ApiResult<?> saveNearbyPackage(@RequestBody ClyjNearbyPackageVo clyjNearbyPackageVo,MultipartFile[]  packageBanner,MultipartFile mainPushPic) throws Exception{
		 ApiResult<?> r=  clyjNearbyPackageService.saveNearbyPackage(clyjNearbyPackageVo,packageBanner,mainPushPic);
		  return r;
	  }
	  /**
      * 删除团购商品
      *
      * @param id
      */
	  @RequestMapping("/deleteById/{packageId}")
     public void delClyjUser(@PathVariable String packageId) {
         this.clyjNearbyPackageService.deleteById(packageId);
     }
     /****
	   * 批量删除
	   * @param 
	   * @return
	 * @throws Exception 
	 */
	  @RequestMapping("/batchDelete")
	  @ResponseBody
	  public ApiResult<?> batchDelete(@RequestBody String[] packageIdArr) throws Exception{
		 ApiResult<?> r=  clyjNearbyPackageService.batchDelete(packageIdArr);
		  return r;
	  }
     /****
	   * 批量下架
	   * @param 
	   * @return
	 * @throws Exception 
	 */
	  @RequestMapping("/batchPullOffShelves")
	  @ResponseBody
	  public ApiResult<?> batchPullOffShelves(@RequestBody String[] packageIdArr) throws Exception{
		 ApiResult<?> r=  clyjNearbyPackageService.batchPullOffShelves(packageIdArr);
		  return r;
	  }
	  /****
	   * 单个上架
	   * @param 
	   * @return
	 * @throws Exception 
	 */
	  @RequestMapping("/putOnsale")
	  @ResponseBody
	  public ApiResult<?> putOnsale(@RequestBody String packageId,String type) throws Exception{
		 ApiResult<?> r=  clyjNearbyPackageService.putOnsale(packageId,type);
		  return r;
	  }
	  /****
	   * 校验唯一主推（点击主推时调用）
	   * @param 
	   * @return
	 * @throws Exception 
	 */
	  @RequestMapping("/cheeckOnlyMainPush")
	  @ResponseBody
	  public ApiResult<?> cheeckOnlyMainPush(@RequestBody JSONObject param) throws Exception{
		 String mainPush=param.getString("mainPush");
		  ApiResult<?> r=  clyjNearbyPackageService.cheeckOnlyMainPush(mainPush);
		  return r;
	  }
}

